package com.sy.service.impl;

import com.sy.dto.JsonResult;
import com.sy.entity.Blog;
import com.sy.entity.BlogExample;
import com.sy.mapper.BlogMapper;
import com.sy.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserBlogServiceImpl implements com.sy.service.UserBlogService {

    @Autowired
    private HttpUtils httpUtils;

    @Autowired
    private BlogMapper blogMapper;

    @Override
    public JsonResult getBlogsByUserId(Integer userId){
        //根据用户id获取所有的博客


        BlogExample example = new BlogExample();
        BlogExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userId);

        List<Blog> blogs = blogMapper.selectByExample(example);
        return httpUtils.buildSuccess(200,blogs);
    }



    @Override
    public JsonResult removeBlogsByid(Integer blogid){
        //根据用户id获取所有的博客


        Integer result = blogMapper.deleteByPrimaryKey(blogid);

        return httpUtils.buildSuccess(204,result);
    }







}
